package cmd

import (
	"context"
	"diygw-ui-go/internal/controller/v1/admin"
	"diygw-ui-go/internal/v1/bll"
	admin2 "diygw-ui-go/internal/v1/model/admin"
	"diygw-ui-go/internal/v1/model/entity"
	"diygw-ui-go/internal/v1/service"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server()
			s.Group("/", func(group *ghttp.RouterGroup) {
				group.Middleware(
					//service.Middleware().Ctx,
					bll.Middleware().CORS,
					//service.Middleware().ResponseHandler,
				)
				group.Bind(
					admin.SysUser.Login,
				)
				//获取系统菜单
				group.GET("/admin/index/getMenuAdmin", func(r *ghttp.Request) {
					_list, _ := service.SysMenu().GetMenuAdmin(ctx, 1)
					_map := g.Map{
						"code": 200,
						"msg":  "success",
						"data": _list,
						//"total": 17,
					}

					r.Response.WriteJson(_map)
				})
				//后台用户列表
				group.POST("/sys/user/list", func(r *ghttp.Request) {
					_page_num := r.Get("pageNum").Int()
					_page_size := r.Get("pageSize").Int()
					_out, _ := service.SysUser().GetListPage(ctx, admin2.SysUserlistInput{PageNum: _page_num, PageSize: _page_size})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"rows":  _out.List,
						"total": _out.Total,
					}
					r.Response.WriteJson(_map)
				})
				//后台部门列表
				group.POST("/sys/dept/list", func(r *ghttp.Request) {
					_page_num := r.Get("pageNum").Int()
					_page_size := r.Get("pageSize").Int()
					_out, _ := service.SysDept().GetListPage(ctx, admin2.SysDeptlistInput{PageNum: _page_num, PageSize: _page_size})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"rows":  _out.List,
						"total": _out.Total,
					}
					r.Response.WriteJson(_map)
				})
				//后台岗位列表
				group.POST("/sys/post/list", func(r *ghttp.Request) {
					_page_num := r.Get("pageNum").Int()
					_page_size := r.Get("pageSize").Int()
					_out, _ := service.SysPost().GetListPage(ctx, admin2.SysPostlistInput{PageNum: _page_num, PageSize: _page_size})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"rows":  _out.List,
						"total": _out.Total,
					}
					r.Response.WriteJson(_map)
				})
				//后台字典列表
				group.POST("/sys/dict/list", func(r *ghttp.Request) {
					_page_num := r.Get("pageNum").Int()
					_page_size := r.Get("pageSize").Int()
					_out, _ := service.SysDict().GetListPage(ctx, admin2.SysDictlistInput{PageNum: _page_num, PageSize: _page_size})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"rows":  _out.List,
						"total": _out.Total,
					}
					r.Response.WriteJson(_map)
				})
				//后台参数设置列表
				group.POST("/sys/config/list", func(r *ghttp.Request) {
					_page_num := r.Get("pageNum").Int()
					_page_size := r.Get("pageSize").Int()
					_out, _ := service.SysConfig().GetListPage(ctx, admin2.SysConfiglistInput{PageNum: _page_num, PageSize: _page_size})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"rows":  _out.List,
						"total": _out.Total,
					}
					r.Response.WriteJson(_map)
				})
				//后台角色列表
				group.POST("/sys/role/list", func(r *ghttp.Request) {
					_page_num := r.Get("pageNum").Int()
					_page_size := r.Get("pageSize").Int()
					_out, _ := service.SysRole().GetListPage(ctx, admin2.SysRolelistInput{PageNum: _page_num, PageSize: _page_size})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"rows":  _out.List,
						"total": _out.Total,
					}
					r.Response.WriteJson(_map)
				})
				//后台菜单列表
				group.POST("/sys/menu/list", func(r *ghttp.Request) {
					_out, _ := service.SysMenu().GetList(ctx, admin2.SysMenulistInput{SysMenu: entity.SysMenu{Status: "0"}})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"rows":  _out.List,
						"total": _out.Total,
					}
					r.Response.WriteJson(_map)
				})
				//后台字典列表
				group.GET("/sys/dictData/list", func(r *ghttp.Request) {
					_dict_type := r.Get("dictType").String()
					_out, _ := service.SysDictData().GetList(ctx, admin2.SysDictDatalistInput{SysDictData: entity.SysDictData{Status: "0", DictType: _dict_type}})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"total": _out.Total,
						"rows":  _out.List,
					}
					r.Response.WriteJson(_map)
				})
				//后台登录日志
				group.POST("/log/logins/list", func(r *ghttp.Request) {
					_page_num := r.Get("pageNum").Int()
					_page_size := r.Get("pageSize").Int()
					_out, _ := service.LogLogins().GetListPage(ctx, admin2.LogLoginslistInput{PageNum: _page_num, PageSize: _page_size})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"rows":  _out.List,
						"total": _out.Total,
					}
					r.Response.WriteJson(_map)
				})
				//后台操作日志
				group.POST("/log/operations/list", func(r *ghttp.Request) {
					_page_num := r.Get("pageNum").Int()
					_page_size := r.Get("pageSize").Int()
					_out, _ := service.LogOperations().GetListPage(ctx, admin2.LogOperationslistInput{PageNum: _page_num, PageSize: _page_size})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"rows":  _out.List,
						"total": _out.Total,
					}
					r.Response.WriteJson(_map)
				})
				//后台代码列表
				group.POST("/sys/database/list", func(r *ghttp.Request) {
					_page_num := r.Get("pageNum").Int()
					_page_size := r.Get("pageSize").Int()
					_out, _ := service.SysDataBase().GetListPage(ctx, admin2.SysDatabaselistInput{PageNum: _page_num, PageSize: _page_size})
					_map := g.Map{
						"code":  200,
						"msg":   "success",
						"rows":  _out.List,
						"total": _out.Total,
					}
					r.Response.WriteJson(_map)
				})
			})
			s.Run()
			return nil
		},
	}
)
